package com.len.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateFormatUtils {
    private static final Logger logger = LoggerFactory.getLogger(DateFormatUtils.class);

    /**
     * 日期转换成String类型的格式
     *
     * @param date
     * @return
     */
    public static String DateToString(Date date) {
        SimpleDateFormat format = new SimpleDateFormat(BaseConstants.DATE_STYLE);
        return format.format(date);
    }

    public static Date createDate(String value, String patten) {
        SimpleDateFormat format = new SimpleDateFormat(patten);
        Date parse = null;
        try {
            parse = format.parse(value);
        } catch (ParseException e) {
            logger.info("DateFormatUtils：", e.getMessage());
        }
        return parse;
    }
    public static Date createTimestamp(String value, String patten) {
        SimpleDateFormat format = new SimpleDateFormat(patten);
        Timestamp timestamp = null;
        try {
            Date parse = format.parse(value);
            timestamp = new Timestamp(parse.getTime());
        } catch (ParseException e) {
            logger.info("DateFormatUtils：", e.getMessage());
        }
        return timestamp;
    }
}
